<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 11/8/15
 * Time: 5:56 PM
 */

namespace Printer\Controller;


class PrinterController
{
    function job($PrintName,$ComputerName,$JobID,$PageNumber,$JobName){
        $PrintLogModel = M('PrintLog','print_');
        $PrinterModel = M('Printer','print_');
        $PrinterID = $PrinterModel->where(['Name'=>$PrintName,'ComputerName'=>$ComputerName])->getField('PrinterID');
        if(!$PrinterID){
            $PrinterID = $PrinterModel->add([
                'Name'=>$PrintName,
                'ComputerName'=>$ComputerName,
                'RegTime'=>time(),
                'IP'=>get_client_ip(1)
            ]);
        }
        if($PrinterID){
            $Log = $PrintLogModel->where(['JobID'=>$JobID,'PrinterID'=>$PrinterID])->find();
            if($Log){}else{if($PageNumber)
                $PrintLogModel->add([
                    'PrinterID'=>$PrinterID,
                    'DocumentName'=>$JobName,
                    'JobID'=>$JobID,
                    'PageNumber'=>$PageNumber,
                    'Time'=>time()
                ]);
            }
        }
    }
}